package com.yc.cloud.admin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.cloud.admin.service.UmsAdminRoleRelationService;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.entity.UmsAdminRoleRelation;
import com.yc.cloud.mapper.UmsAdminRoleRelationMapper;
import jakarta.annotation.Resource;
import lombok.val;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 后台用户和角色关系表 服务实现类
 * </p>
 *
 * @author JackGu
 * @since 2022-09-11
 */
@Service
public class UmsAdminRoleRelationServiceImpl extends ServiceImpl<UmsAdminRoleRelationMapper, UmsAdminRoleRelation> implements UmsAdminRoleRelationService {

      @Resource
      private UmsAdminRoleRelationMapper umsAdminRoleRelationMapper;
        @Override
        public IPage<UmsAdminRoleRelation> list(BasePageReqDTO queryParam) {
        val query = new QueryWrapper<UmsAdminRoleRelation>();
        IPage<UmsAdminRoleRelation> page;
        //排序
        if (StrUtil.isNotEmpty(queryParam.getSortBy())) {
        if (BasePageReqDTO.ORDER_DESC.equals(queryParam.getOrder())) {
        query.orderByDesc(UmsAdminRoleRelation.ID);
        } else if (BasePageReqDTO.ORDER_ASC.equals(queryParam.getOrder())) {
        query.orderByAsc(UmsAdminRoleRelation.ID);
        }
        }
        //模糊查询
        if (StrUtil.isNotEmpty(queryParam.getKeyword())) {
        query.and(queryWrapper -> {

        });
        }
        //分页
        if (queryParam.getPage()) {
        page = new Page<>(queryParam.getPageNum(), queryParam.getPageSize(), true);
        } else {
        page = new Page<>(queryParam.getPageNum(), umsAdminRoleRelationMapper.selectCount(query), true);
        }
        return umsAdminRoleRelationMapper.selectPage(page, query);
        }
}
